<?php
#                                                                           
# author: Cody Sorgenfrey                                       
# (c)2012 South Hill Calvary Chapel                                               
#                                                                                
include_once("./root.inc.php");
include_once("${root}/mysql/database_info.php");
include_once("${root}/mysql/common.php");
include_once("${root}/common.php");

$title = "All the needs in the selected category.";
$meta_key=null;
$meta_desc=null;
print_html_head($title ,$meta_key,$meta_desc);
print_java_head(null);

begin_body();
page_title_no_content($title);

if ($_REQUEST['needsLogin'] == 1){
	
	if ($_GET['cat']){
			
		connect_select_test("needs");
		
		$result = mysql_query("SELECT * FROM `needs` WHERE `category`='".$_GET['cat']."' && `pending`='0' ORDER BY `postDate` DESC");
			
		if (!$result){
			
			printf("Sorry the category you're looking for no longer exists or hasn't been approved yet.");
		} 
		else {
			
			printf("<button style='float:right; margin-top:-30px;' onclick='refreshPage(\"/needsPost.php\")'>Post a Need</button>\n");
					
			while($need = mysql_fetch_array($result)){
				
				$postDate = date("D, M jS, Y", strtotime($need['postDate']));
	
				printf("<a style='text-decoration:none; font-style:normal;' href='/needsPosted.php?id=%s'><div class='content'><h4>%s</h4><p>%s<br><br>%s</p></div></a>\n", $need['id'], $need['title'],$postDate, $need['summary']);
			}
		}
	}
	else {
	
		printf("<script type='text/javascript'>window.location = '/needs.php';</script>");
	}
}
else {
		
	printf("<div class='content'>\n");
	
	$vars = array("cat", $_GET['cat']);
	
	printNeedsLogin("/needsCategory.php?cat=".$_GET['cat']."", $vars);
	
	printf("</div>\n");
}
	
end_page_title();
end_body();
?>